package com.iotproject.eduservice.service.impl;

import com.iotproject.eduservice.entity.EduTeacher;
import com.iotproject.eduservice.mapper.EduTeacherMapper;
import com.iotproject.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-11-02
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {

    //得到所有讲师列表
    @Override
    public Map<String, Object> getTeacherFrontList(Page<EduTeacher> pageTeacher) {
        QueryWrapper<EduTeacher> eduTeacherQueryWrapper = new QueryWrapper<>();
        eduTeacherQueryWrapper.orderByDesc("id");
        IPage<EduTeacher> eduTeacherIPage = baseMapper.selectPage(pageTeacher, eduTeacherQueryWrapper);
        //手动实现分页（不使用Element-ui），需要这些数据
        List<EduTeacher> records = pageTeacher.getRecords();
        long current = pageTeacher.getCurrent();
        long pages = pageTeacher.getPages();
        long size = pageTeacher.getSize();
        long total = pageTeacher.getTotal();
        boolean hasNext = pageTeacher.hasNext();//下一页
        boolean hasPrevious = pageTeacher.hasPrevious();//上一页
        //封装到map里
        Map<String, Object> maps = new HashMap<>();
        maps.put("items", records);
        maps.put("current", current);
        maps.put("pages", pages);
        maps.put("size", size);
        maps.put("total", total);
        maps.put("hasNext", hasNext);
        maps.put("hasPrevious", hasPrevious);

        return maps;
    }
}
